#ifndef _H_S_TASK_PROCESSOR_H_
#define _H_S_TASK_PROCESSOR_H_

#include "../typedefine.h"
#include "STask.h"

namespace TB
{
	template<typename T>
	struct STaskProcessor
	{
		friend class CTaskHelper;
	public:
		STaskProcessor():
			m_bIsNull(true)
		{
		}
	private:
		STaskProcessor(bool bNull):
			m_bIsNull(bNull)
		{
		}

	public:
		STaskProcessor(const STaskProcessor& roProcessor) noexcept : m_sTask(roProcessor.m_sTask), m_bIsNull(roProcessor.m_bIsNull) {}
		STaskProcessor& operator=(const STaskProcessor& roProcessor) noexcept { m_sTask = roProcessor.m_sTask; m_bIsNull = roProcessor.m_bIsNull; return *this; }
		STaskProcessor(STaskProcessor&& roProcessor) noexcept : m_sTask(std::move(roProcessor.m_sTask)), m_bIsNull(roProcessor.m_bIsNull) {}
		STaskProcessor& operator=(STaskProcessor&& roProcessor) noexcept { m_sTask = std::move(roProcessor.m_sTask); m_bIsNull = roProcessor.m_bIsNull; return *this; }
	public:
		inline STask<T>& GetTask() const
		{
			return m_sTask;
		}
		inline bool Resolve(T&& oData) const
		{
			return m_sTask.m_poInfo->Resolve(std::forward<T>(oData));
		}
		inline bool Resolve(const T& oData) const
		{
			return m_sTask.m_poInfo->Resolve(oData);
		}
		inline explicit operator bool() const noexcept 
		{
			return !m_bIsNull;
		}

	private:
		mutable STask<T> m_sTask;
		bool m_bIsNull = false;
	};

	template<>
	struct STaskProcessor<void>
	{
		friend class CTaskHelper;
	public:
		STaskProcessor():
			m_sTask(true), m_bIsNull(true)
		{
		}

	private:
		STaskProcessor(bool bNull):
			m_sTask(bNull), m_bIsNull(bNull)
		{
		}
	public:
		STaskProcessor(const STaskProcessor& roProcessor) noexcept : m_sTask(roProcessor.m_sTask), m_bIsNull(roProcessor.m_bIsNull) {}
		STaskProcessor& operator=(const STaskProcessor& roProcessor) noexcept { m_sTask = roProcessor.m_sTask; m_bIsNull = roProcessor.m_bIsNull; return *this; }
		STaskProcessor(STaskProcessor&& roProcessor) noexcept : m_sTask(std::move(roProcessor.m_sTask)), m_bIsNull(roProcessor.m_bIsNull) {}
		STaskProcessor& operator=(STaskProcessor&& roProcessor) noexcept { m_sTask = std::move(roProcessor.m_sTask); m_bIsNull = roProcessor.m_bIsNull; return *this; }
	public:
		inline STask<void>& GetTask() const
		{
			return m_sTask;
		}
		inline bool Resolve() const
		{
			return m_sTask.m_poInfo->Resolve();
		}
		inline explicit operator bool() const noexcept 
		{
			return !m_bIsNull;
		}

	private:
		mutable STask<void> m_sTask;
		bool m_bIsNull = false;
	};
}

#endif
